<?php
/*
 * Add an resource to db
 * @author Tuong Tran <tuong.tran@outlook.com>
 */
?>
<?php $this->breadcrumbs = array(
    'Resource Manager' => array('/resource/index'),
    'Add new'
) ?>
<style>
    .external{display: none}
</style>
<ul class="nav nav-tabs">
    <li >
        <a href="<?php echo url('/resource/index', array('mode' => $this->mode)) ?>">
            <i class="splashy-hcards"></i>
            Manage resource
        </a>
    </li>
    <li  class="active">
        <a href="#">
            <i class="splashy-document_small_upload"></i> Upload Media
        </a>
    </li>
</ul>
<div class="tab-content">
    <div class="tab-pane active" id="manage">
        <?php $form = $this->beginWidget('CActiveForm', array(
            'id' => 'gallery-item-external-form',
            'htmlOptions' => array(
                'class' => 'form-horizontal'
            )
        )) ?>

        <?php echo $form->errorSummary($resource) ?>

        <div class="control-group">
            <label class="control-label">Option</label>
            <div class="controls">
                <select name="option" id="media-option">
                    <option value="local">Upload from computer</option>
                    <option value="external" <?php if($isExternal) echo 'selected' ?>>From external</option>
                </select>
            </div>
        </div>
        <div class="control-group external">
            <label class="control-label">Select file type<span class="required">*</span></label>
            <div class="controls">
                <?php echo $form->dropDownList($resource, 'resource_type', Resource::getTypes()) ?>
            </div>
        </div>
        <div class="control-group external">
            <label class="control-label">Resource Name <span class="required">*</span></label>
            <div class="controls">
                <?php echo $form->textField($resource, 'resource_name', array('class' => 'input-xxlarge')) ?>
                <p class="help-block">Enter full name</p>
            </div>
        </div>
        <div class="control-group external">
            <label class="control-label">Description</label>
            <div class="controls">
                <?php echo $form->textArea($resource, 'resource_description', array('class' => 'input-xxlarge')) ?>
                <p class="help-block">Enter description here</p>
            </div>
        </div>
        <div class="control-group external">
            <label class="control-label">Resource path <span class="required">*</span></label>
            <div class="controls">
                <?php echo $form->textField($resource, 'resource_path', array('class' => 'input-xxlarge')) ?>
                <p class="help-block">Enter fully external link here</p>
            </div>
        </div>
        <div class="control-group external">
            <label class="control-label"></label>
            <div class="controls">
                <input type="submit" value="Upload" class="btn btn-primary" />
            </div>
        </div>

        <?php $this->endWidget() ?>

        <div id="xupload-form">
            <?php
            $this->widget('common.extensions.xupload.XUpload', array(
                'url' => url('/resource/upload'), //upload to a gallery
                'model' => $xupload,
                'attribute' => 'file',
                'multiple' => true,
            ));
            ?>
        </div>

    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        <?php if($isExternal) : ?>
        $("#xupload-form").hide();
        $(".external").show();
        <?php endif; ?>
        $("#media-option").change(function(){
            if($(this).val()=='local'){
                $("#xupload-form").show();
                $(".external").hide();
            }else{
                $("#xupload-form").hide();
                $(".external").show();
            }
        });
    });

</script>
